<?php
/**
 * Created by PhpStorm.
 * User: eeo
 * Date: 2017/6/9
 * Time: 20:17
 */

namespace App\Model\Marketing;

use Illuminate\Support\Facades\DB;
use Illuminate\Database\Eloquent\Model;

class Order extends Model
{
    const CANCELLED = 0;      #取消的
    const UNPAID = 1;         #未支付
    const CONFIRMED = 2;      #已确认支付
    const PAID = 3;           #已支付/支付成功
    const ASSIGNED = 4;       #已分班
    const EXPIRED = 5;        #已过期

    const CLASSE = 1;   #班课
    const DEMO = 2;     #约课

    # 数据表
    protected $table = 'orders';

    # PK
    protected $primaryKey = 'id';

    # fillable fields
    protected $fillable = [
        'type',
        'studentid',
        'mobile',
        'studentname',
        'productid',
        'productname',
        'status',
        'orderdate',
        'description',
        'amount'
    ];


    /**
     * 获取约课待分班学生
     * @return mixed
     */
    static function getAvalidAppointOrderStudents()
    {
        $results   =  DB::table('orders')
            ->select(DB::raw('students.*, orders.id as orderid, orders.productid'))
            ->join('students', 'students.studentuid', '=', 'orders.studentid')
            ->where('type', Order::DEMO)
            ->where('status', Order::PAID)
            ->get();
        return $results;
    }

}